<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>施工团队</title>
    <style>
    </style>
</head>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=IENn7ABARjQIkTeAKyh80VTkg2jYXf3K"></script>
<body>


<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a href="javascript:">首页</a><span lay-separator="">/</span>
        <a href="javascript:">施工团队</a><span lay-separator="">/</span>
        <a><cite>考勤管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>
<div class="x-body" style="margin: 20px auto auto 15px;">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <a href="base/link/@/constructionTeam/att_management/att_management.jhtml" class="layui-btn">考勤列表</a>
            <a href="base/link/@/constructionTeam/att_management/checkwork.jhtml" class="layui-btn layui-btn-warm">考勤逐日统计</a>
            <% if (session.om_user.sysRole.sysRoleCode.id==2||session.om_user.sysRole.sysRoleCode.id==3){%>
            <a href="base/link/@/constructionTeam/att_management/checkwork_month.jhtml" class="layui-btn">考勤月平均值统计</a>
            <%}%>
        </div>
    </div>

    <div style="margin-left: -15px;" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <input type="hidden"  value="${session.om_user.team_id}" id="a_tid" name="a_tid">
            <input type="hidden"  value="${session.om_user.sysRole.sysRoleCode.id}" id="role_id">
            <input type="hidden"  value="${session.om_user.enterprise.id}" id="e_id">
            <% if (session.om_user.sysRole.sysRoleCode.id==3){%>
            <input type="hidden"  value="${session.area.id}" id="area_id">
            <%}%>

            <div class="layui-input-inline">
                <input type="text" name="starttime" id="startTime" placeholder="查询考勤月份" autocomplete="off" class="layui-input" >
            </div>
            <!--<div class="layui-input-inline" style="width: auto;">-->
                <!--~-->
            <!--</div>-->
            <!--<div class="layui-input-inline">-->
                <!--<input type="text" id="endTime" name="endtime" placeholder="查询结束月份" autocomplete="off" class="layui-input" >-->
            <!--</div>-->
            <% if (session.om_user.sysRole.sysRoleCode.id==2||session.om_user.sysRole.sysRoleCode.id==3){%>
            <div class="layui-input-inline" >
                <select type="text" name="a_name" id="a_name1" autocomplete="off" class="layui-select">
                </select>
            </div>
            <%}%>
            <!--<% if (session.om_user.sysRole.sysRoleCode.id==4){%>
            <div class="layui-input-inline" >
                <input disabled type="text" value="${session.om_user.constructionTeam.t_name}" name="a_name" id="a_name" placeholder="请输入队伍名称" autocomplete="off" class="layui-input" >
            </div>
            <%}%>-->
            <div class="layui-input-inline">
                <button  class="layui-btn layui-btn-checked" lay-submit="" lay-filter="LAY-user-front-search"  ><i class="layui-icon layui-icon-search"></i>查询</button>
            </div>
        </div>
    </div>

    <div class="layui-table-main layui-form" style="height: 100%">
        <table id="myTableData" lay-filter="myTableData"  class="layui-hide"></table>
        <div id="test1"></div>
    </div>
</div>
<!--考勤列表-->
<div class="layui-fluid">
    <div class="layui-card">
        <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
    </div>
    <div class="layui-card">
        <table class="layui-table" >
            <thead>
            </thead>
            <tbody>
            <tr>
                <td colspan="2" style="background-color: #009688;color: white">
                    <% if (session.om_user.sysRole.sysRoleCode.id==4){%>
                        <span>${session.om_user.constructionTeam.t_name}</span><span id="month"></span>月逐日人数柱状图
                    <%}%>
                    <% if (session.om_user.sysRole.sysRoleCode.id==2||session.om_user.sysRole.sysRoleCode.id==3){%>
                    <span id="team_name"></span><span id="months"></span>月逐日人数柱状图
                    <%}%>
                </td>
            </tr>
            <tr >
                <td colspan="2" ><div id="container4"  style="height:400px"></div></td>
            </tr>
            </tbody>
        </table>
    </div>

</div>
<script id="demo4" type="text/html">
    <option value="">请选择施工队</option>
    {{#  layui.each(d.list4, function(index, item4){ }}

    <option value="{{ item4.t_name }}">{{ item4.t_name }}</option>

    {{#  }); }}
    {{#  if(d.list4.length === 0){ }}
    无数据
    {{#  } }}
</script>
<%include("/common/foot.html"){}%>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
<!--施工队月逐日人数柱状图-->
<script type="text/javascript">
    var a_tid = $("#a_tid").val();
    var role_id = $("#role_id").val();
    var e_id = $("#e_id").val();
    var area_id = $("#area_id").val();
    $.ajax({
        url: "system/att_checkwork/statis.json",
        type: "POST",
        data: {
            a_tid: a_tid,
            role_id:role_id,
            e_id:e_id,
            area_id: area_id,
        },
        dataType: "json",
        success: function (data) {
            // alert(JSON.stringify(data))
            let worklist = [];
            let daylist = [];
            if(role_id==4){
                $("#month").text(data.month);
            }else if(role_id==2||role_id==3){
                $("#months").text(data.month);
                $("#team_name").text("所有施工队");
            }
            for(var i =0;i<data.worklist.length;i++){
                worklist.push(data.worklist[i]);
            }
            for(var k =0;k<data.daylist.length;k++){
                daylist.push(data.daylist[k]);
            }
            var dom = document.getElementById("container4");
            var myChart = echarts.init(dom);
            var app = {};
            option = null;
            option = {
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['2020']
                },
                toolbox: {
                    show: true,
                    feature: {
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line', 'bar']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        data: daylist
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                    }
                ],
                series: [
                    {
                        name: '出勤人数',
                        type: 'bar',
                        data: worklist
                    }
                ]
            };
            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        }
    });
</script>
<!--考勤列表-->
<script>
    layui.use(['index', 'table', 'form', 'laydate', 'AliangLayui'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        var title = "添加考勤";
        var findAll_url = 'system/att_checkwork/findAll.json';
        var find_Cols = 'system/att_checkwork/findCols.json'
        // var cols = [ //考勤列表表头
        //     /*{checkbox: true, fixed: true},*/
        //     {
        //         totalRowText: '合计：',
        //         unresize: true,
        //         field: 't_createDate',
        //         sort:'true' ,
        //         fixed: 'left',
        //         templet: "<div>{{layui.util.toDateString(d.t_createDate, 'yyyy-MM-dd ')}}</div>",
        //         title: '考勤日期',
        //     },
        //     {field: 'a_name',  title: '施工队伍'},
        //     {field: 'a_should_num',  title: '应到人数',totalRow: true},
        // ];



        var a_tid = $("#a_tid").val();
        var e_id = $("#e_id").val();
        var role_id = $("#role_id").val();
        var area_id = $("#area_id").val();
        var mycols = new Array;
        $.ajax({
            url: find_Cols,
            type: "POST",
            data: {
                a_tid: a_tid,
                e_id: e_id,
                role_id: role_id,
                area_id: area_id,
            },
            async:false,
            dataType: "json",
            success: function (ret) {
                if(ret.code==0){
                    for(var i =0;i<ret.data.length;i++) {
                        mycols[0] = {
                            totalRowText: '合计：',
                            unresize: true,
                            field: 't_createDate',
                            sort: 'true',
                            fixed: 'left',
                            title: '考勤日期',
                            align: 'center',
                            templet: "<div>{{layui.util.toDateString(d.a_createDate, 'yyyy-MM-dd ')}}</div>",
                        };
                        if(role_id==4){
                            mycols[1] = {
                                field: 'a_should_num',
                                title: '应到人数',
                                align: 'center',
                                totalRow: true,
                            };
                        }else if(role_id==2||role_id==3){
                            mycols[1] = {
                                field: 'a_should_num',
                                title: '应到人数',
                                align: 'center',
                                totalRow: true,
                            };
                        }
                        if(role_id==4){
                            mycols[2] = {
                                field: 'a_pm_num',
                                title: '实到人数',
                                align: 'center',
                                totalRow: true,
                                templet: "<div>{{d.a_pm_num==null||d.a_pm_num==''?'<p style='color: red'>下午未考勤</p>':parseInt(d.a_pm_num)}}</div>",
                            };
                        } else if(role_id==2||role_id==3){
                            mycols[2] = {
                                field: 'a_pm_num',
                                title: '实到人数',
                                align: 'center',
                                totalRow: true,
                                templet: "<div>{{d.a_pm_num==null||d.a_pm_num==''?'<p style='color: red'>下午未考勤</p>':parseInt(d.a_pm_num)}}</div>",
                            };
                        }
                        if(role_id==4){
                            mycols[3] = {
                                field: 'a_abs_num',
                                title: '缺勤人数',
                                align: 'center',
                                totalRow: true,
                                templet: "<div>{{d.a_pm_num==null||d.a_pm_num==''?'<p style='color: red'>下午未考勤</p>':parseInt(d.a_abs_num)}}</div>",
                            };
                        } else if(role_id==2||role_id==3){
                            mycols[3] = {
                                field: 'a_abs_num',
                                title: '缺勤人数',
                                align: 'center',
                                totalRow: true,
                                templet: "<div>{{d.a_pm_num==null||d.a_pm_num==''?'<p style='color: red'>下午未考勤</p>':parseInt(d.a_abs_num)}}</div>",
                            };
                        }
                        if(role_id==4){
                            mycols[4] = {
                                field: 'a_absence',
                                title: '状态',
                                align: 'center',
                                templet: "<div>{{d.a_absence==0?'<p style='color: green'>满勤</p>':'<p style='color: red'>缺勤</p>'}}</div>",
                            };
                        } else if(role_id==2||role_id==3){
                            mycols[4] = {
                                field: 'a_absence',
                                title: '状态',
                                align: 'center',
                                templet: "<div>{{d.a_absence==0?'<p style='color: green'>满勤</p>':'<p style='color: red'>缺勤</p>'}}</div>",
                            };
                        }
                        if(role_id==4){
                            mycols[5] = {
                                field: 'a_name',
                                title: '队伍名称',
                                align: 'center',
                            };
                        } else if(role_id==2||role_id==3){
                            mycols[5] = {
                                field: 'a_name',
                                title: '队伍名称',
                                align: 'center',
                            };
                        }
                    }
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
            }
        });

        //搜索栏队伍
        var eid = $("#e_id").val();
        var roleid = $("#role_id").val();
        if(roleid==3){
            var areaid = $("#area_id").val();
        }
        $.ajax({
            url: "system/constructionTeam/findAreaTeam.json",
            type: "POST",
            data: {
                eid:eid,
                roleid:roleid,
                areaid:areaid
            },
            dataType: "json",
            success: function (ret4) {
                var laytpl = layui.laytpl;
                var rets = { //数据
                    "list4": ret4.data,
                };
                laytpl($("#demo4").html()).render(rets, function (html) {
                    $("#a_name1").html(html);
                });
                form.render();
            },
            error: function (jqXHR, textStatus, errorThrown) {

            }
        });

        //考勤列表
        table.render({
            elem: '#LAY-user-manage',
            id: 'listReload',
            toolbar: '#toolbarDemo',
            title: title,
            url: findAll_url,
            page: true, //开启分页
            limits: [10, 20, 30, 50], //控制多少行一页（默认五条一页）
            totalRow: true,//开启合计行
            defaultToolbar: ['filter', 'print', 'exports'],
            cols: [mycols],
            where:{
                a_tid:$("#a_tid").val(),
                e_id:$("#e_id").val(),
                role_id:$("#role_id").val(),
                area_id:$("#area_id").val()
            },
            done: function (res, curr, count) {


                //将合计数值去小数点
                $(".layui-table-total div").each(function (i,item) {
                    var div_text = $(item).html();
                    var value; //转换后的值
                    if(div_text != "") {
                        value = parseInt(div_text);
                        if(!isNaN(value)) {
                            $(item).html(parseInt(div_text));
                        }
                    }
                });
            }
        });

        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;
            var a_tid = $("#a_tid").val();
            var e_id = $("#e_id").val();
            var role_id = $("#role_id").val();
            var area_id = $("#area_id").val();
            var mycols = new Array;
            $.ajax({
                url: find_Cols,
                type: "POST",
                data: {
                    a_tid: a_tid,
                    e_id: e_id,
                    role_id: role_id,
                    area_id: area_id,
                    starttime: field.starttime,
                    a_name: field.a_name
                },
                async:false,
                dataType: "json",
                success: function (ret) {
                    if(ret.code==0){
                        for(var i =0;i<ret.data.length;i++) {
                            mycols[0] = {
                                totalRowText: '合计：',
                                unresize: true,
                                field: 't_createDate',
                                sort: 'true',
                                fixed: 'left',
                                title: '考勤日期',
                                align: 'center',
                                templet: "<div>{{layui.util.toDateString(d.a_createDate, 'yyyy-MM-dd ')}}</div>",
                            };
                            mycols[1] = {
                                field: 'a_should_num',
                                title: ret.data[0].a_name+'应到人数',
                                align: 'center',
                                totalRow: true,
                            };
                            mycols[2] = {
                                field: 'a_pm_num',
                                title: ret.data[0].a_name+'实到人数',
                                align: 'center',
                                totalRow: true,
                                templet: "<div>{{d.a_pm_num==null||d.a_pm_num==''?'<p style='color: red'>下午未考勤</p>':parseInt(d.a_pm_num)}}</div>",
                            };
                            mycols[3] = {
                                field: 'a_abs_num',
                                title: ret.data[0].a_name+'缺勤人数',
                                align: 'center',
                                totalRow: true,
                                templet: "<div>{{d.a_pm_num==null||d.a_pm_num==''?'<p style='color: red'>下午未考勤</p>':parseInt(d.a_abs_num)}}</div>",
                            };
                            mycols[4] = {
                                field: 'a_absence',
                                title: ret.data[0].a_name+'是否缺勤',
                                align: 'center',
                                templet: "<div>{{d.a_absence==0?'<p style='color: green'>满勤</p>':'<p style='color: red'>缺勤</p>'}}</div>",
                            };

                        };
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                }
            });
            var a_tid = $("#a_tid").val();
            var role_id = $("#role_id").val();
            var e_id = $("#e_id").val();
            var area_id = $("#area_id").val();
            $.ajax({
                url: "system/att_checkwork/statis.json",
                type: "POST",
                data: {
                    a_tid: a_tid,
                    role_id: role_id,
                    e_id:e_id,
                    area_id: area_id,
                    starttime: field.starttime,
                    a_name: field.a_name
                },
                dataType: "json",
                success: function (data) {
                    if(role_id==4){
                        $("#month").text(data.month);
                    }else if(role_id==2||role_id==3){
                        $("#months").text(data.month);
                        $("#team_name").text(data.team);
                    }
                    let worklist = [];
                    let daylist = [];
                    for(var i =0;i<data.worklist.length;i++){
                        worklist.push(data.worklist[i]);
                    }
                    for(var k =0;k<data.daylist.length;k++){
                        daylist.push(data.daylist[k]);
                    }
                    var dom = document.getElementById("container4");
                    var myChart = echarts.init(dom);
                    var app = {};
                    option = null;
                    option = {
                        tooltip: {
                            trigger: 'axis'
                        },
                        legend: {
                            data: ['2020']
                        },
                        toolbox: {
                            show: true,
                            feature: {
                                dataView: {show: true, readOnly: false},
                                magicType: {show: true, type: ['line', 'bar']},
                                restore: {show: true},
                                saveAsImage: {show: true}
                            }
                        },
                        calculable: true,
                        xAxis: [
                            {
                                type: 'category',
                                data: daylist
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value',
                            }
                        ],
                        series: [
                            {
                                name: '出勤人数',
                                type: 'bar',
                                data: worklist
                            }
                        ]
                    };
                    if (option && typeof option === "object") {
                        myChart.setOption(option, true);
                    }
                }
            });
            //执行重载
            table.reload('listReload', {
                where: {
                    starttime: field.starttime,
                    // endtime: field.endtime,
                    a_name: field.a_name
                },
                page: {
                    curr: 1//重新从第 1 页开始
                },
                cols: [mycols]//重载时必须重新定义表头为自己定义的表头，否则默认layui表头，无法渲染
            });
        });

        //执行laydate
        var startDate = laydate.render({
            elem: '#startTime', //指定元素
            type: 'month',
            done: function(value, date){
                // 结束时间大于开始时间
                if( value !== '' ){
                    endDate.config.min.year = date.year;
                    endDate.config.min.month = date.month - 1;
                    endDate.config.min.date = date.date;
                }else{
                    endDate.config.min.year = '';
                    endDate.config.min.month = '';
                    endDate.config.min.date = '';
                }
            }
        });
        //执行laydate
        var endDate = laydate.render({
            elem: '#endTime', //指定元素
            type: 'month',
            done:function (value,date) {
                //  开始时间小于结束时间
                if( value !== '' ){
                    startDate.config.max.year = date.year;
                    startDate.config.max.month = date.month - 1;
                    startDate.config.max.date = date.date;
                }else{
                    startDate.config.max.year = '';
                    startDate.config.max.month = '';
                    startDate.config.max.date = '';
                }
            }
        });

        //初始化日期模块
        laydate.render({
            elem: '#createDate' //指定元素
        });

        //头工具栏事件
        table.on('toolbar(LAY-user-manage)', function (obj) {
            switch (obj.event) {
                case 'export':
                layer.msg("导出");
                break;
            }
        });
    });
</script>

</body>

</html>
